<template>
  <div class="app-container">
    <el-row :gutter="10">
      <el-col :xs="24" :sm="18" :md="14" :lg="10" :xl="8">
        <div style="text-align: center;margin-bottom: 10px">绑定OpenId</div>
        <el-form :model="openForm" ref="openForm" :rules="openFormRules" label-width="80px">
          <el-form-item label="openId" prop="openId">
            <el-input type="text" maxlength="11"  v-model="openForm.openId" placeholder="请输入openId"></el-input>
          </el-form-item>
        </el-form>
        <div  style="text-align: center" class="dialog-footer">
          <el-button @click="cancelUp">取 消</el-button>
          <el-button :loading="addLoading" type="primary" @click="updateOpenId">修 改</el-button>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {updateInUser, updateMobile} from "@/api/enterprise";
import store from "@/store";

export default {
  name: "bindOpenId",
  data(){
    return{
      openForm:{
        openId:""
      },
      addLoading:false,
      openFormRules:{

      }
    }
  },
  computed:{
    openId(){
        return this.$store.getters.userInfo.openId;
      }
  },
  created() {
      this.openForm.openId = this.openId
  },
  methods:{
    cancelUp(){
      window.history.back()
    },
    updateOpenId(){
      this.addLoading = true
      this.$refs['openForm'].validate(valid => {
        if (valid){
          updateInUser(this.openForm).then(res=>{
            this.addLoading = false
            this.$notify.success({
              title: '成功',
              message: "更新OpenId成功"
            })
            store.dispatch('user/getInfo')
            this.cancelUp()
          }).catch(res=>{
            this.addLoading = false
            this.$notify.error({
              title: '失败',
              message: res.msg
            })
          })
        }else {
          this.addLoading = false
          console.log("表单验证不通过")
        }
      })
    }
  }
}
</script>

<style scoped>

</style>